package com.example.demo.service;

import com.example.demo.dao.ArticleMapper;
import com.example.demo.model.Articleinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleService {
    @Autowired//属性注入
    ArticleMapper articleMapper;
    //通过uid来在articleinfo表中查询对应的文章信息
    public List<Articleinfo> getListByuid(int uid){
        return articleMapper.getListByuid(uid);
    }
    //通过文章id来删除文章
    public int del(Integer aid,int uid){
        return articleMapper.del(aid,uid);
    }
    //添加文章
    public int add(Articleinfo articleinfo){
        return articleMapper.add(articleinfo);
    }
    //通过文章id和对应的用户uid来查询文章
    public Articleinfo getArticleByIdAndUid(int aid,int uid){
        return articleMapper.getArticleByIdAndUid(aid,uid);
    }
    //修改文章
    public int update(Articleinfo articleinfo){
        return articleMapper.update(articleinfo);
    }
    //根据id查询文章信息
    public Articleinfo getDatailById(Integer aid){
       return articleMapper.getDatailById(aid);
    }
    //根据uid查询用户发布的文章数量,使用聚合查询
    public int getArtCountById(int uid){
        return articleMapper.getArtCountById(uid);
    }

    //通过id修改文章阅读量属性
    public int incrementRCount(int aid){
        return articleMapper.incrementRCount(aid);
    }

    //通过psize和分页公式算出的offset来实现分页查询
   public List<Articleinfo> getListByPage(int psize,int offset){
        return articleMapper.getListByPage(psize,offset);
    }

    //统计文章数量
    public int getCount(){
        return articleMapper.getCount();
    }

}
